//
//  JYEmptyView.m
//  JYFarm
//
//  Created by 花花 on 2017/10/17.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYEmptyView.h"

@interface JYEmptyView()

////空
//@property (nonatomic) UIImageView * imgView;
////提示label
//@property (nonatomic) UILabel * messageLabel;
////去购物
//@property (nonatomic) UIButton * shopBtn;

@property (nonatomic, strong) UILabel * messageLabel;

@property (nonatomic, strong) UIImageView * icon;



@end
@implementation JYEmptyView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self)
    {
        [self initUI];
    }
    
    return self;
}

- (void)initUI
{
    self.backgroundColor = [UIColor clearColor];
    
    self.icon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 140, 133)];
    self.icon.centerX = self.centerX;
    self.icon.centerY = self.centerY -64;
    self.icon.image = [UIImage imageNamed:@"mine_background"];
    [self addSubview:self.icon];
    
    self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.icon.frame)+20,Screen_Width, 15)];
    self.messageLabel.textAlignment = NSTextAlignmentCenter;
    self.messageLabel.textColor = k6Color;
    [self addSubview:self.messageLabel];
}

+ (JYEmptyView*)searchEmptyForView:(UIView*)view
{
    NSArray * subViews = view.subviews;
    
    JYEmptyView * empView = nil;
    
    for (UIView * subView in subViews)
    {
        if ([subView isKindOfClass:[JYEmptyView class]])
        {
            empView = (JYEmptyView*)subView;
            return empView;
        }
    }
    
    return empView;
}
+ (void)showEmptyInView:(UIView *)view WithMessage:(NSString *)message
{
    JYEmptyView * empView = [JYEmptyView searchEmptyForView:view];
    if (empView)
    {
        empView.hidden = NO;
    }
    else
    {
        empView = [[self alloc]initWithFrame:view.bounds];
    }
    
    empView.messageLabel.text = message;
    
    [view addSubview:empView];
}

+ (void)showEmptyInView:(UIView*)view WithMessage:(NSString*)message image:(NSString *)imageName{
    JYEmptyView * empView = [JYEmptyView searchEmptyForView:view];
    if (empView)
    {
        empView.hidden = NO;
    }
    else
    {
        empView = [[self alloc]initWithFrame:view.bounds];
    }
    
    empView.messageLabel.text = message;
    empView.icon.image = [UIImage imageNamed:imageName];
    
    [view addSubview:empView];
}

+ (void)hiddenEmptyInView:(UIView *)view
{
    JYEmptyView * empView = [JYEmptyView searchEmptyForView:view];
    if (empView) {
        empView.hidden = YES;
        [empView removeFromSuperview];
    }
}

//- (instancetype)initWithFrame:(CGRect)frame{
//    
//    if (self = [super initWithFrame:frame]){
//        [self initUI];
//        
//        [self initConstraints];
//    }
//    
//    return self;
//}
//- (void)initConstraints{
//
//    JYWeakSelf;
//    
//    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//         make.centerX.mas_equalTo(weakSelf.mas_centerX);
//        make.centerY.mas_equalTo(weakSelf.centerY);
//    }];
//
//    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.width.mas_equalTo(94);
//        make.height.mas_equalTo(94);
//        make.centerX.mas_equalTo(weakSelf.mas_centerX);
//        make.bottom.mas_equalTo(weakSelf.messageLabel.mas_top).offset(-50);
//    }];
//    
//    [self.shopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//       
//        make.top.mas_equalTo(weakSelf.messageLabel.mas_bottom).offset(17);
//        make.width.mas_equalTo(130);
//        make.height.mas_equalTo(40);
//        make.centerX.mas_equalTo(weakSelf.mas_centerX);
//
//        
//    }];
//
//}
//
//- (void)initUI
//{
//    self.backgroundColor = [UIColor clearColor];
//    
//    
//    [self addSubview:self.imgView];
//    [self addSubview:self.messageLabel];
//    [self addSubview:self.shopBtn];
////    UIImageView * icon = [[UIImageView alloc]initWithFrame:CGRectMake((Screen_Width-94)/2, 120, 94, 98)];
////    icon.image = [UIImage imageNamed:@"mine_background"];
////    [self addSubview:icon];
////    
////    self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(icon.frame)+54,Screen_Width, 15)];
////    self.messageLabel.textAlignment = NSTextAlignmentCenter;
////    self.messageLabel.font = kFont(14);
////    self.messageLabel.textColor = k9Color;
////    [self addSubview:self.messageLabel];
////    
////    self.shopBtn = [UIButton jy_buttontitle:@"" titleColor:kThemeColor frame:CGRectMake(0, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>) target:<#(id)#> action:<#(SEL)#> fontSize:<#(CGFloat)#> bgImageName:<#(NSString *)#>]
////}
//}
//-  (UIImageView *)imgView{
//
//    if (!_imgView) {
//        _imgView = [[UIImageView alloc]init];
//        _imgView.image = [UIImage imageNamed:@"mine_background"];
//    }
//    return _imgView;
//
//}
//- (UILabel *)messageLabel{
//
//    if (!_messageLabel) {
//        _messageLabel = [UILabel labelText:@"" fontSize:14 textColor:k9Color textAlignment:NSTextAlignmentCenter];
//    }
//
//    return _messageLabel;
//}
//- (UIButton *)shopBtn{
//
//    if (!_shopBtn) {
//        _shopBtn  = [UIButton buttonWithType:UIButtonTypeCustom];
//        [_shopBtn setTitle:@"去购物" forState:UIControlStateNormal];
//        [_shopBtn addTarget:self action:@selector(goshopOnClick) forControlEvents:UIControlEventTouchUpInside];
//        [_shopBtn setBackgroundImage:[UIImage imageNamed:@"mine_shopping"] forState:UIControlStateNormal];
//
//    }
//    return _shopBtn;
//
//}
//- (void)goshopOnClick{
//
//    if (_btnHanderOnClick) {
//        _btnHanderOnClick();
//    }
//
//}
//+ (JYEmptyView*)searchEmptyForView:(UIView*)view
//{
//    NSArray * subViews = view.subviews;
//    
//    JYEmptyView * empView = nil;
//    
//    for (UIView * subView in subViews)
//    {
//        if ([subView isKindOfClass:[JYEmptyView class]])
//        {
//            empView = (JYEmptyView*)subView;
//            return empView;
//        }
//    }
//    
//    return empView;
//}
//+ (void)showEmptyInView:(UIView *)view WithMessage:(NSString *)message 
//{
//    JYEmptyView * empView = [JYEmptyView searchEmptyForView:view];
//    if (empView)
//    {
//        empView.hidden = NO;
//    }
//    else
//    {
//        empView = [[self alloc]initWithFrame:view.bounds];
//    }
//    
//    empView.messageLabel.text = message;
//    
//    [view addSubview:empView];
//}
//
//+ (void)hiddenEmptyInView:(UIView *)view
//{
//    JYEmptyView * empView = [JYEmptyView searchEmptyForView:view];
//    if (empView) {
//        empView.hidden = YES;
//        [empView removeFromSuperview];
//    }
//}


@end
